//
//  BuyOrderContentDetailViewController.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/17.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "BuyOrderContentDetailViewController.h"
#import "GoodsInformationViewController.h"
#import "ShippingAddressAddViewController.h"

@interface BuyOrderContentDetailViewController ()

@property (strong, nonatomic) UIScrollView *goodsContentScrollView;

// 物流信息
@property (strong, nonatomic) UIView *addressView;
@property (strong, nonatomic) UIView *logisticsView;
@property (strong, nonatomic) UIImageView *logisticsIV;
@property (strong, nonatomic) UILabel *logisticsStatusL;
@property (strong, nonatomic) UILabel *logisticsNewTimeL;
@property (strong, nonatomic) UIImageView *rightArrowIV;

// 地址栏
@property (strong, nonatomic) UIImageView *topLineIV;
@property (strong, nonatomic) UIImageView *bottomLineIV;
@property (strong, nonatomic) UIImageView *addressImageV;
@property (strong, nonatomic) UILabel *receiverL;
@property (strong, nonatomic) UILabel *phoneL;
@property (strong, nonatomic) UILabel *addressL;

// 商品栏
/** 标题*/
@property (strong, nonatomic) UILabel *titleL;
/**
 状态
 */
@property (strong, nonatomic) UILabel *statusL;

/** 图片*/
@property (strong, nonatomic) UIImageView *goodsIV;

/** 商品标题 */
@property (strong, nonatomic) UILabel *nameL;

/** 金额钱的logo*/
@property (strong, nonatomic) UIImageView *moneyLogoIV;

/** 金额*/
@property (strong, nonatomic) UILabel *moneyL;

/** 数量的图片*/
@property (strong, nonatomic) UIImageView *countIV;

/** 数量*/
@property (strong, nonatomic) UILabel *countL;

@property (strong, nonatomic) UILabel *rankL;

// 商品相关信息
// 快递费用（配送方式）
@property (strong, nonatomic) UILabel *shipMethodL;
@property (strong, nonatomic) UILabel *shipMethod;
// 积分抵消（商品总价）
@property (strong, nonatomic) UILabel *goodsTotolMoneyL;
@property (strong, nonatomic) UILabel *goodsTotolMoney;
// 商品总价（下单时间）
@property (strong, nonatomic) UILabel *orderTimeL;
@property (strong, nonatomic) UILabel *orderTime;
// 下单时间（订单编号）
@property (strong, nonatomic) UILabel *orderNumL;
@property (strong, nonatomic) UILabel *orderNum;
// 订单标号（支付方式）
@property (strong, nonatomic) UILabel *payMethodL;
@property (strong, nonatomic) UILabel *payMethod;
// 支付方式（备注）
@property (strong, nonatomic) UILabel *remarkL;
@property (strong, nonatomic) UILabel *remark;
// 取消订单
@property (strong, nonatomic) UIImageView *cancleOrderIV;
@property (strong, nonatomic) UILabel *cancleOrderL;
// 立即支付
@property (strong, nonatomic) UIImageView *payOrderIV;
@property (strong, nonatomic) UILabel *payOrderL;

@property (strong, nonatomic) NSDictionary *contentDict;

//用于砍价分享
@property (strong, nonatomic) NSString *bargain_id;
//用于拼团分享
@property (strong, nonatomic) NSString *spellidsstr;
@end
@implementation BuyOrderContentDetailViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (@available(iOS 11.0, *)) {
        [[UIScrollView appearance] setContentInsetAdjustmentBehavior:UIScrollViewContentInsetAdjustmentNever];
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
    
    self.view.backgroundColor = WhiteColor;
    self.title = @"订单详情";
    
    self.statusL.hidden = YES;
    
    [self loadDetailData];

    [self createUIWithType:self.tradeType];
    
#warning 设置scrollview的contentSize
    
    self.goodsContentScrollView.contentSize = CGSizeMake(0, HEIGHT * 2);
    
    self.cancleOrderL.hidden = YES;
    self.cancleOrderIV.hidden = YES;
    
    
    
}

#pragma mark -页面数据显示
- (void)loadDetailData {
    
    // 商品id
    NSString *sid = [RSA encryptString:[NSString stringWithFormat:@"%@", self.dict[@"sid"]] publicKey:PublicKey];
    // 收货地址id
    NSString *addressid = [RSA encryptString:[NSString stringWithFormat:@"%@", self.dict[@"addressid"]] publicKey:PublicKey];
    // 用户id
    NSString *userid = [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey];
    // 购买数量
    NSString *number = [RSA encryptString:@"1" publicKey:PublicKey];
    // 运费
    NSString *kdmoney = [RSA encryptString:self.dict[@"kdmoney"] publicKey:PublicKey];
    
    NSString *str = [NSString stringWithFormat:@"{\"sid\" : \"%@\", \"addressid\" : \"%@\", \"userid\" : \"%@\", \"number\" : \"%@\", \"kdmoney\" : \"%@\"}", sid, addressid, userid, number, kdmoney];
    
    NSString *url = @"";
    if (self.type == 1) {// 开团
        url = @"groupbuy/groupbuy/createOrder";
        
    }else {
       
        // 砍价 的url
        url = @"bargain/bargaingoods/createOrderApp";
    }
    

    [PPNetworkHelper POST:url parameters:@{@"json" : str} success:^(id responseObject) {
        
        NSLog(@"订单详情页数据：%@", responseObject);
    
        if ([responseObject[@"code"] integerValue] == 1) {
            
            NSDictionary *dict = responseObject[@"data"];

            self.contentDict = [NSDictionary dictionaryWithDictionary:dict];
            self.bargain_id = dict[@"bargain_id"];
            self.receiverL.text = dict[@"username"];
            self.phoneL.text = dict[@"phone"];
            self.addressL.text = dict[@"address"];
            self.titleL.text = dict[@"dianpu"];
            
            NSString *str = dict[@"title"];
            NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
            NSMutableParagraphStyle *pargStyle = [[NSMutableParagraphStyle alloc] init];
            [pargStyle setLineSpacing:jisuan(5)];
            [attributeStr addAttribute:NSParagraphStyleAttributeName value:pargStyle range:NSMakeRange(0, str.length)];
            self.nameL.attributedText = attributeStr;
            self.nameL.lineBreakMode = NSLineBreakByTruncatingTail;
            
            NSString *picStr = @"";
            if ([dict[@"pic"] hasPrefix:@"http://"] || [dict[@"pic"] hasPrefix:@"https://"]) {
                picStr = dict[@"pic"];
                
            }else {
                picStr = [NSString stringWithFormat:@"http://%@", dict[@"pic"]];
                
            }
            
            [self.goodsIV sd_setImageWithURL:[NSURL URLWithString:picStr]];

//            self.rankL.text = [NSString stringWithFormat:@"分类：%@", dict[@"classname"]];
            
//            self.rankL.hidden = YES;
            self.moneyL.text = dict[@"price"];
            self.countL.text = dict[@"number"];
//            self.shipMethod.text = dict[@"kdmoney"];
            self.goodsTotolMoney.text = dict[@"dintegral"];
            self.orderTime.text = dict[@"money"];
            self.orderNum.text = dict[@"create_time"];
            self.payMethod.text = dict[@"ddid"];
            
        }else if ([responseObject[@"code"] integerValue] == 13) {
            
            // 没有收货地址
            ShippingAddressAddViewController *vc = [[ShippingAddressAddViewController alloc] init];
            
            [self.navigationController pushViewController:vc animated:YES];
            
        }else {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:responseObject[@"msg"]];
            
        }
        
    } failure:^(NSError *error) {
        
        if (error) {
            
            [[KYAlertView sharedInstance] showAlertViewWithMessage:Tip];
        }
    }];
    
}

#pragma mark -立即支付接口

- (void)gotoPay:(NSInteger)type {
    NSLog(@"======== %@",self.dict);
    NSString *userid = [RSA encryptString:[CommonUserInfo sharedInstance].user_id publicKey:PublicKey];
    NSString *s1 = self.contentDict[@"money"];
    NSString *s2 = self.contentDict[@"price"];
    NSString *price = @"";
    if(s1.length > 0) {
        price = s1;
    }else {
        price = s2;
    }
    NSString *money = [RSA encryptString:price publicKey:PublicKey];
    NSString *ddid = [RSA encryptString:[NSString stringWithFormat:@"%@", self.contentDict[@"ddid"]] publicKey:PublicKey];
    NSString *paytype = [RSA encryptString:@"1" publicKey:PublicKey];
    NSString *addressid = [RSA encryptString:[NSString stringWithFormat:@"%@", self.dict[@"addressid"]] publicKey:PublicKey];
    NSString *kdmoney = [RSA encryptString:[NSString stringWithFormat:@"%@", self.contentDict[@"kdmoney"]] publicKey:PublicKey];
    NSString *bean = [RSA encryptString:[NSString stringWithFormat:@"%@", self.contentDict[@"dintegral"]] publicKey:PublicKey];
  
    NSString *str = [NSString stringWithFormat:@"{\"userid\" : \"%@\", \"money\" : \"%@\", \"ddid\" : \"%@\", \"paytype\" : \"%@\", \"addressid\" : \"%@\", \"kdmoney\" : \"%@\",\"bean\" : \"%@\"}", userid, money, ddid, paytype, addressid, kdmoney, bean];
    WS(weakSelf);
    [[CommonAction sharedInstance] gotoPay:str type:type andReturnBlock:^(id result) {
        
        TalkingDataOrder *order = [TalkingDataOrder createOrder:weakSelf.contentDict[@"ddid"] total:[weakSelf.contentDict[@"money"] floatValue] * 100 currencyType:@"CNY"];
        [order addItem:weakSelf.dict[@"id"] category:weakSelf.contentDict[@"classname"] name:weakSelf.contentDict[@"title"] unitPrice:[weakSelf.contentDict[@"money"] floatValue] * 100 amount:1];
        [TalkingData onOrderPaySucc:[CommonUserInfo sharedInstance].user_id payType:@"Alipay" order:order];
    
        

        WebViewController *vc = [[WebViewController alloc] init];
        //vc.title = @"详情";
        if (self.type == 1) { // 开团
 
            NSString *url = @"/groupbuy/groupbuy/payStatus";
            NSString *str = [NSString stringWithFormat:@"{\"ddid\" : \"%@\"}", ddid];
            [PPNetworkHelper POST:url parameters:@{@"json" : str} success:^(id responseObject) {
                if ([responseObject[@"code"] integerValue] == 1) {
            
                self.spellidsstr = responseObject[@"data"][@"spellid"];
                    
                vc.url = [NSString stringWithFormat:@"%@%@?spellid=%@&userid=%@", ebaseH5,@"success.html", self.spellidsstr, [CommonUserInfo sharedInstance].user_id];
                    if (vc) {
                        NSMutableArray * array =[[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
                        //删除最后一个，也就是自己
                        [array removeObjectAtIndex:array.count-1];
                        
                        //添加要跳转的controller
                        [array addObject:vc];
                        [self.navigationController setViewControllers:array animated:YES];
                        //                        [self.navigationController pushViewController:vc animated:YES];
                    }
                }
                
            } failure:^(NSError *error) {

            }];

        }else{ //砍价
            
         vc.url = [NSString stringWithFormat:@"%@%@?bargain_id=%@&userid=%@&type=1", ebaseH5,@"bargain.html", self.bargain_id, [CommonUserInfo sharedInstance].user_id];
            if (vc) {
                NSMutableArray * array =[[NSMutableArray alloc]initWithArray:self.navigationController.viewControllers];
                //删除最后一个，也就是自己
                [array removeObjectAtIndex:array.count-1];
                
                //添加要跳转的controller
                [array addObject:vc];
                [self.navigationController setViewControllers:array animated:YES];
            }
        }
        
    }];
}

#pragma mark -物流信息查看
- (void)logisticsGestureClick:(UITapGestureRecognizer *)recognizer {
    
    NSLog(@"物流信息查看");
    
    GoodsInformationViewController *informationIV = [[GoodsInformationViewController alloc] init];
    [self.navigationController pushViewController:informationIV animated:YES];
    
}

#pragma mark -取消订单
- (void)cancleGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"取消订单");
    
}

#pragma mark -立即支付
- (void)payOrderGestureClick:(UIGestureRecognizer *)recognizer {
    
    NSLog(@"立即支付");
    
    [self gotoPay:self.type];
    
//    if (self.tradeType == 0) {
//
//        NSLog(@"立即支付");
//
//    }else {
//
//        NSLog(@"联系客服");
//
//    }
    
}

- (void)createUIWithType:(NSInteger)type {
    
    self.cancleOrderIV.hidden = YES;
    self.cancleOrderL.hidden = YES;
    
    if (self.tradeType == 3) {
        
        self.cancleOrderL.text = @"删除订单";
        self.payOrderL.text = @"再次购买";
    
    }else {
        
        self.cancleOrderL.text = @"取消订单";
        
        if (self.tradeType == 0) {
            
            self.payOrderL.text = @"立即支付";
        }else {
            
            self.payOrderL.text = @"再次购买";
        }
    }
    
    if (self.tradeType == 3 || self.tradeType == 2) {
        
        self.logisticsView.hidden = NO;
        
        if (self.tradeType == 2) {
            
            self.logisticsIV.image = [UIImage imageNamed:@"goodsSendBG"];
        }else {
            
           self.logisticsIV.image = [UIImage imageNamed:@"goodsSignIN"];
            
        }
        
    }else {
        
        self.logisticsView.hidden = YES;
    }
    
    [self.view addSubview:self.goodsContentScrollView];
    
    [self.view addSubview:self.logisticsView];
    [self.logisticsView addSubview:self.logisticsIV];
    [self.logisticsView addSubview:self.logisticsStatusL];
    [self.logisticsView addSubview:self.logisticsNewTimeL];
    [self.logisticsView addSubview:self.rightArrowIV];
    
    [self.view addSubview:self.addressView];
    [self.addressView addSubview:self.topLineIV];
    [self.addressView addSubview:self.bottomLineIV];
    [self.addressView addSubview:self.addressImageV];
    [self.addressView addSubview:self.receiverL];
    [self.addressView addSubview:self.phoneL];
    [self.addressView addSubview:self.addressL];
    
    [self.view addSubview:self.titleL];
    [self.view addSubview:self.statusL];
    [self.view addSubview:self.goodsIV];
    [self.view addSubview:self.moneyL];
    [self.view addSubview:self.moneyLogoIV];
    [self.view addSubview:self.nameL];
    [self.view addSubview:self.rankL];
    [self.view addSubview:self.countIV];
    [self.view addSubview:self.countL];
    
    [self.view addSubview:self.shipMethodL];
    [self.view addSubview:self.shipMethod];
    [self.view addSubview:self.goodsTotolMoneyL];
    [self.view addSubview:self.goodsTotolMoney];
    [self.view addSubview:self.orderTimeL];
    [self.view addSubview:self.orderTime];
    [self.view addSubview:self.orderNumL];
    [self.view addSubview:self.orderNum];
    [self.view addSubview:self.payMethodL];
    [self.view addSubview:self.payMethod];
    [self.view addSubview:self.remarkL];
    [self.view addSubview:self.remark];
    
    [self.view addSubview:self.cancleOrderIV];
    [self.view addSubview:self.cancleOrderL];
    [self.view addSubview:self.payOrderIV];
    [self.view addSubview:self.payOrderL];
    
    __weak typeof(self) weakSelf = self;
    [self.goodsContentScrollView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(0);
        make.bottom.mas_equalTo(weakSelf.view.mas_bottom);
    }];
    [self.logisticsView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        make.top.mas_equalTo(weakSelf.goodsContentScrollView.mas_top);
        make.height.mas_equalTo(jisuan(158));
    }];
    [self.logisticsIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.logisticsView.mas_left).with.offset(jisuan(40));
        make.centerY.mas_equalTo(weakSelf.logisticsView.mas_centerY);
        make.width.mas_equalTo(jisuan(40));
        make.height.mas_equalTo(jisuan(40));
    }];
    [self.rightArrowIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.logisticsView.mas_right).with.offset(-jisuan(40));
        make.centerY.mas_equalTo(weakSelf.logisticsView.mas_centerY);
        make.width.mas_equalTo(jisuan(34));
        make.height.mas_equalTo(jisuan(22));
    }];
    [self.logisticsStatusL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.logisticsIV.mas_right).with.offset(jisuan(40));
        make.right.mas_equalTo(weakSelf.rightArrowIV.mas_left).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.logisticsView.mas_top).with.offset(jisuan(40));
    }];
    [self.logisticsNewTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.logisticsIV.mas_right).with.offset(jisuan(40));
        make.right.mas_equalTo(weakSelf.rightArrowIV.mas_left).with.offset(-jisuan(40));
        make.bottom.mas_equalTo(weakSelf.logisticsView.mas_bottom).with.offset(-jisuan(40));
        
    }];
    
    [self.addressView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left);
        make.right.mas_equalTo(weakSelf.view.mas_right);
        if (self.logisticsView.hidden) {
            make.top.mas_equalTo(weakSelf.goodsContentScrollView.mas_top).with.offset(jisuan(40));
            
        }else {
            make.top.mas_equalTo(weakSelf.logisticsView.mas_bottom);
            
        }
        make.height.mas_equalTo(jisuan(154));
    }];
    
    [self.topLineIV mas_makeConstraints:^(MASConstraintMaker *make) {
    
 
        make.top.mas_equalTo(weakSelf.addressView.mas_top).with.offset(jisuan(1));
        make.centerX.mas_equalTo(weakSelf.addressView.mas_centerX);

        make.width.mas_equalTo(jisuan(680));
        make.height.mas_equalTo(jisuan(4));
    }];
    [self.bottomLineIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.bottom.mas_equalTo(weakSelf.addressView.mas_bottom);
//        make.centerX.mas_equalTo(weakSelf.addressView.mas_centerX);
//        make.width.mas_equalTo(jisuan(680));
        
        make.left.mas_equalTo(weakSelf.topLineIV.mas_left);
        make.right.mas_equalTo(weakSelf.topLineIV.mas_right);
        make.height.mas_equalTo(jisuan(4));
    }];
    
    [self.addressImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.addressView.mas_left).with.offset(jisuan(40));
        make.centerY.mas_equalTo(weakSelf.addressView.mas_centerY);
        make.width.mas_equalTo(jisuan(34));
        make.height.mas_equalTo(jisuan(40));
        
    }];

    [self.receiverL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.addressImageV.mas_right).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.addressView.mas_top).with.offset(jisuan(30));
        
    }];
    [self.phoneL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.receiverL.mas_right).with.offset(jisuan(20));
        make.top.mas_equalTo(weakSelf.addressView.mas_top).with.offset(jisuan(30));
        
    }];
    [self.addressL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.receiverL.mas_left);
        make.bottom.mas_equalTo(weakSelf.addressView.mas_bottom).with.offset(-jisuan(30));
        
    }];

    [self.titleL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.addressView.mas_bottom).with.offset(jisuan(60));
        
    }];
    
    [self.statusL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.addressView.mas_bottom).with.offset(jisuan(60));
    }];
    
    [self.goodsIV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.titleL.mas_bottom).with.offset(jisuan(20));
        make.width.mas_equalTo(jisuan(120));
        make.height.mas_equalTo(jisuan(120));
    }];
    
    [self.moneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.statusL.mas_bottom).with.offset(jisuan(20));

        
    }];
    
    [self.moneyLogoIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.moneyL.mas_left).with.offset(-jisuan(10));
        make.centerY.mas_equalTo(weakSelf.moneyL.mas_centerY);
        make.width.mas_equalTo(jisuan(14));
        make.height.mas_equalTo(jisuan(18));
    }];
    
    [self.nameL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.goodsIV.mas_right).with.offset(jisuan(30));
        make.top.mas_equalTo(weakSelf.goodsIV.mas_top);
//        make.right.mas_equalTo(weakSelf.moneyLogoIV.mas_left).with.offset(-jisuan(30));
        make.width.mas_equalTo(jisuan(300));
        
    }];
    [self.rankL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.nameL.mas_left);
        make.bottom.mas_equalTo(weakSelf.goodsIV.mas_bottom);
    }];
    
    
    [self.countL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.moneyL.mas_bottom).with.offset(jisuan(22));
        
    }];
    [self.countIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.countL.mas_left).with.offset(-jisuan(10));
        make.centerY.mas_equalTo(weakSelf.countL.mas_centerY);
        make.width.mas_equalTo(jisuan(14));
        make.height.mas_equalTo(jisuan(14));
        
    }];
    [self.shipMethodL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.goodsIV.mas_bottom).with.offset(jisuan(30));
    }];
    [self.shipMethod mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.shipMethodL.mas_top);
    }];
    [self.goodsTotolMoneyL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.shipMethodL.mas_bottom).with.offset(jisuan(30));
    }];
    [self.goodsTotolMoney mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.goodsTotolMoneyL.mas_top);
    }];
    
    [self.orderTimeL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.goodsTotolMoneyL.mas_bottom).with.offset(jisuan(30));
    }];
    [self.orderTime mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.orderTimeL.mas_top);
    }];
    [self.orderNumL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.orderTimeL.mas_bottom).with.offset(jisuan(30));
    }];
    [self.orderNum mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.orderNumL.mas_top);
    }];
    [self.payMethodL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.orderNumL.mas_bottom).with.offset(jisuan(30));
    }];
    [self.payMethod mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.payMethodL.mas_top);
    }];
    
    [self.remarkL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.view.mas_left).with.offset(jisuan(40));
        make.top.mas_equalTo(weakSelf.payMethodL.mas_bottom).with.offset(jisuan(30));
    }];
    [self.remark mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.remarkL.mas_top);
    }];
    
    [self.payOrderIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.view.mas_right).with.offset(-jisuan(40));
        make.top.mas_equalTo(weakSelf.remarkL.mas_bottom).with.offset(jisuan(106));
    }];
    [self.payOrderL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.payOrderIV.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.payOrderIV.mas_centerY);
        
    }];
    
    [self.cancleOrderIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.right.mas_equalTo(weakSelf.payOrderIV.mas_left).with.offset(-jisuan(30));
        make.top.mas_equalTo(weakSelf.payOrderIV.mas_top);
        
    }];
    
    [self.cancleOrderL mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.cancleOrderIV.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.cancleOrderIV.mas_centerY);
        
    }];

}


#pragma mark -lazy

- (UIScrollView *)goodsContentScrollView {
    
    if (!_goodsContentScrollView) {
        
        _goodsContentScrollView = [[UIScrollView alloc] init];
        _goodsContentScrollView.backgroundColor = WhiteColor;
        
    }
    
    return _goodsContentScrollView;
}

- (UIView *)logisticsView {
    
    if (!_logisticsView) {
        
        // 79
        _logisticsView = [[UIView alloc] init];
        _logisticsView.backgroundColor = WhiteColor;
        
        UITapGestureRecognizer *logisticsGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(logisticsGestureClick:)];
        [_logisticsView addGestureRecognizer:logisticsGesture];
    }
    
    return _logisticsView;
}

- (UIImageView *)logisticsIV {
    
    if (!_logisticsIV) {
        
        _logisticsIV = [[UIImageView alloc] init];
        _logisticsIV.contentMode = UIViewContentModeScaleAspectFit;
        _logisticsIV.image = [UIImage imageNamed:@"goodsSendBG"];
   
    }
    
    return _logisticsIV;
}
- (UILabel *)logisticsStatusL {
    
    if (!_logisticsStatusL) {
    
        _logisticsStatusL = [[UILabel alloc] init];
        _logisticsStatusL.textAlignment = NSTextAlignmentLeft;
        _logisticsStatusL.textColor = Color6ac20b;
        _logisticsStatusL.font = Font(24);
        _logisticsStatusL.text = @"您的订单已发货";
    }
    
    return _logisticsStatusL;
}
- (UILabel *)logisticsNewTimeL {
    
    
    if (!_logisticsNewTimeL) {
        
        _logisticsNewTimeL = [[UILabel alloc] init];
        _logisticsNewTimeL.textColor = Color9b9b9b;
        _logisticsNewTimeL.textAlignment = NSTextAlignmentLeft;
        _logisticsNewTimeL.text = @"2018-06-30 15:12:23";
        _logisticsNewTimeL.font = Font(24);
    }
    
    return _logisticsNewTimeL;
    
}

- (UIImageView *)rightArrowIV {
    if (!_rightArrowIV) {
        
        _rightArrowIV = [[UIImageView alloc] init];
        _rightArrowIV.contentMode = UIViewContentModeScaleAspectFit;
        _rightArrowIV.image = [UIImage imageNamed:@"buyRightArrowBG"];
    }
    
    return _rightArrowIV;
    
}

- (UIView *)addressView {
    
    if (!_addressView) {
        
        _addressView = [[UIView alloc] init];
        _addressView.backgroundColor = WhiteColor;
    }
    
    return _addressView;
}

- (UIImageView *)topLineIV {
    
    if (!_topLineIV) {
        
        _topLineIV = [[UIImageView alloc] init];
        _topLineIV.contentMode = UIViewContentModeScaleAspectFit;
        _topLineIV.image = [UIImage imageNamed:@"buyContentLinebg"];
    }
    
    return _topLineIV;
}
- (UIImageView *)bottomLineIV {
    
    if (!_bottomLineIV) {
        
        _bottomLineIV = [[UIImageView alloc] init];
        _bottomLineIV.contentMode = UIViewContentModeScaleToFill;
        _bottomLineIV.image = [UIImage imageNamed:@"buyContentLinebg"];
    }
    
    return _bottomLineIV;
}
- (UIImageView *)addressImageV {
    
    if (!_addressImageV) {
        
        _addressImageV = [[UIImageView alloc] init];
        _addressImageV.contentMode = UIViewContentModeScaleToFill;
        _addressImageV.image = [UIImage imageNamed:@"receiverAddressBG"];
    }
    
    return _addressImageV;
}

- (UILabel *)receiverL {
    
    if (!_receiverL) {
        
        _receiverL = [[UILabel alloc] init];
        _receiverL.textColor = Color333333;
        _receiverL.textAlignment = NSTextAlignmentLeft;
        _receiverL.font = Font(28);
        _receiverL.text = @"名字";
        
    }
    
    return _receiverL;
}
- (UILabel *)phoneL {
    
    if (!_phoneL) {
        
        _phoneL = [[UILabel alloc] init];
        _phoneL.textColor = Color333333;
        _phoneL.textAlignment = NSTextAlignmentLeft;
        _phoneL.font = Font(28);
        //_phoneL.text = @"13777778970";
        
    }
    
    return _phoneL;
}
- (UILabel *)addressL {
    
    if (!_addressL) {
        
        _addressL = [[UILabel alloc] init];
        _addressL.textColor = Color333333;
        _addressL.textAlignment = NSTextAlignmentLeft;
        _addressL.font = Font(24);
        //_addressL.text = @"黑龙江省 鹤岗市 东山区滨河社区2号楼2333";
        
    }
    
    return _addressL;
}

- (UILabel *)titleL {
    
    if (!_titleL) {
        
        _titleL = [[UILabel alloc] init];
        //_titleL.text = @"理财店铺";
        _titleL.textAlignment = NSTextAlignmentLeft;
        _titleL.font = Font(24);
        _titleL.textColor = Color333333;
        
    }
    
    return _titleL;
    
}
- (UILabel *)statusL {
    
    if (!_statusL) {
        
        _statusL = [[UILabel alloc] init];
        _statusL.textColor = Colorff4200;
        _statusL.text = @"等待支付";
        _statusL.font = Font(24);
        _statusL.textAlignment = NSTextAlignmentRight;
        _statusL.backgroundColor = WhiteColor;
        
    }
    
    return _statusL;
}
- (UIImageView *)goodsIV {
    
    if (!_goodsIV) {
        
        _goodsIV = [[UIImageView alloc] init];
        _goodsIV.contentMode = UIViewContentModeScaleAspectFit;
        _goodsIV.image = [UIImage imageNamed:@"goodsBG"];
    }
    
    return _goodsIV;
}
- (UILabel *)nameL {
    
    if (!_nameL) {
        
        _nameL = [[UILabel alloc] init];
        _nameL.textColor = Color333333;
        
        _nameL.numberOfLines = 2;
        _nameL.font = Font(24);
        _nameL.textAlignment = NSTextAlignmentLeft;
        _nameL.backgroundColor = WhiteColor;
        
    }
    
    return _nameL;
}

- (UILabel *)moneyL  {
    
    if (!_moneyL) {
        
        _moneyL = [[UILabel alloc] init];
        _moneyL.textColor = Color333333;
//        _moneyL.text = @"99999.00";
        _moneyL.font = Font(24);
        _moneyL.textAlignment = NSTextAlignmentRight;
        _moneyL.backgroundColor = WhiteColor;
        [_moneyL sizeToFit];
        
    }
    
    return _moneyL;
    
}

- (UIImageView *)moneyLogoIV {
    
    if (!_moneyLogoIV) {
        
        _moneyLogoIV = [[UIImageView alloc] init];
        _moneyLogoIV.contentMode = UIViewContentModeScaleAspectFit;
        _moneyLogoIV.image = [UIImage imageNamed:@"moneyLogoBG"];
    }
    
    return _moneyLogoIV;
    
}

- (UILabel *)countL {
    
    if (!_countL) {
        
        _countL = [[UILabel alloc] init];
        _countL.textColor = Color9b9b9b;
        _countL.text = @"1";
        _countL.font = Font(24);
        _countL.textAlignment = NSTextAlignmentRight;
        
        _countL.backgroundColor = WhiteColor;
    }
    
    return _countL;
    
}
- (UIImageView *)countIV {
    
    if (!_countIV) {
        
        _countIV = [[UIImageView alloc] init];
        _countIV.contentMode = UIViewContentModeScaleAspectFit;
        _countIV.image = [UIImage imageNamed:@"countOrderBG"];
    }
    
    return _countIV;
    
}
- (UILabel *)rankL {
    
    if (!_rankL) {
        
        _rankL = [[UILabel alloc] init];
        _rankL.textAlignment = NSTextAlignmentLeft;
        _rankL.textColor = Color9b9b9b;
//        _rankL.text = @"分类：地表最美葡萄酒";
        _rankL.font = Font(20);
        
    }
    
    return _rankL;
}

- (UILabel *)shipMethodL {
    
    if (!_shipMethodL) {
        
        _shipMethodL = [[UILabel alloc] init];
        _shipMethodL.textAlignment = NSTextAlignmentLeft;
        _shipMethodL.textColor = Color333333;
//        _shipMethodL.text = @"配送方式";
        _shipMethodL.text = @"快递费用";
        _shipMethodL.font = Font(24);
        
    }
    
    return _shipMethodL;
    
}

- (UILabel *)shipMethod {
    
    if (!_shipMethod) {
        
        _shipMethod = [[UILabel alloc] init];
        _shipMethod.textAlignment = NSTextAlignmentRight;
        _shipMethod.textColor = Color9b9b9b;
//        _shipMethod.text = @"免邮费";
        _shipMethod.font = Font(24);
        
    }
    
    return _shipMethod;
    
}

- (UILabel *)goodsTotolMoneyL {
    
    if (!_goodsTotolMoneyL) {
        
        _goodsTotolMoneyL = [[UILabel alloc] init];
        _goodsTotolMoneyL.textAlignment = NSTextAlignmentLeft;
        _goodsTotolMoneyL.textColor = Color333333;
//        _goodsTotolMoneyL.textColor = Color1f89ff;
//        _goodsTotolMoneyL.text = @"商品总价";
        _goodsTotolMoneyL.text = @"积分抵消";
        _goodsTotolMoneyL.font = Font(24);
        
    }
    
    return _goodsTotolMoneyL;
    
}

- (UILabel *)goodsTotolMoney {
    
    if (!_goodsTotolMoney) {
        
        _goodsTotolMoney = [[UILabel alloc] init];
        _goodsTotolMoney.textAlignment = NSTextAlignmentRight;
        _goodsTotolMoney.textColor = Color9b9b9b;
//        _goodsTotolMoney.text = @"19990.00元";
        _goodsTotolMoney.textColor = Color1f89ff;
        _goodsTotolMoney.font = Font(24);
        
    }
    
    return _goodsTotolMoney;
    
}
- (UILabel *)orderTimeL {
    
    if (!_orderTimeL) {
        
        _orderTimeL = [[UILabel alloc] init];
        _orderTimeL.textAlignment = NSTextAlignmentLeft;
        _orderTimeL.textColor = Color333333;
//        _orderTimeL.text = @"下单时间";
        _orderTimeL.text = @"商品总价";
        _orderTimeL.font = Font(24);
        
    }
    
    return _orderTimeL;
}

- (UILabel *)orderTime {
    
    if (!_orderTime) {
        
        _orderTime = [[UILabel alloc] init];
        _orderTime.textAlignment = NSTextAlignmentRight;
        _orderTime.textColor = Color9b9b9b;
//        _orderTime.text = @"2018-06-29 15:12:23";
        _orderTime.font = Font(24);
        
    }
    
    return _orderTime;
}
- (UILabel *)orderNumL {
    
    if (!_orderNumL) {
        
        _orderNumL = [[UILabel alloc] init];
        _orderNumL.textAlignment = NSTextAlignmentLeft;
        _orderNumL.textColor = Color333333;
//        _orderNumL.text = @"订单编号";
        _orderNumL.text = @"下单时间";
        _orderNumL.font = Font(24);
        
    }
    
    return _orderNumL;
}

- (UILabel *)orderNum {
    
    if (!_orderNum) {
        
        _orderNum = [[UILabel alloc] init];
        _orderNum.textAlignment = NSTextAlignmentRight;
        _orderNum.textColor = Color9b9b9b;
//        _orderNum.text = @"132874978902374";
        _orderNum.font = Font(24);
        
    }
    
    return _orderNum;
}
- (UILabel *)payMethodL {
    
    if (!_payMethodL) {
        
        _payMethodL = [[UILabel alloc] init];
        _payMethodL.textAlignment = NSTextAlignmentLeft;
        _payMethodL.textColor = Color333333;
//        _payMethodL.text = @"支付方式";
        _payMethodL.text = @"订单编号";
        _payMethodL.font = Font(24);
        
    }
    
    return _payMethodL;
}

- (UILabel *)payMethod {
    
    if (!_payMethod) {
        
        _payMethod = [[UILabel alloc] init];
        _payMethod.textAlignment = NSTextAlignmentRight;
        _payMethod.textColor = Color9b9b9b;
//        _payMethod.text = @"支付宝";
        _payMethod.font = Font(24);
        
    }
    
    return _payMethod;
}

- (UILabel *)remarkL {
    
    if (!_remarkL) {
        
        _remarkL = [[UILabel alloc] init];
        _remarkL.textAlignment = NSTextAlignmentLeft;
        _remarkL.textColor = Color333333;
//        _remarkL.text = @"备注";
        _remarkL.text = @"支付方式";
        _remarkL.font = Font(24);
        
    }
    
    return _remarkL;
}

- (UILabel *)remark {
    
    if (!_remark) {
        
        _remark = [[UILabel alloc] init];
        _remark.textAlignment = NSTextAlignmentRight;
        _remark.textColor = Color9b9b9b;
//        _remark.text = @"加麻加辣";
        _remark.text = @"支付宝";
        _remark.font = Font(24);
        
    }
    
    return _remark;
}

- (UIImageView *)cancleOrderIV {
    
    if (!_cancleOrderIV) {
        
        _cancleOrderIV = [[UIImageView alloc] init];
        _cancleOrderIV.contentMode = UIViewContentModeScaleAspectFit;
        _cancleOrderIV.image = [UIImage imageNamed:@"canclePurchaseBG"];
        
        _cancleOrderIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *cancleGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(cancleGestureClick:)];
        [_cancleOrderIV addGestureRecognizer:cancleGesture];
        
    }
    
    return _cancleOrderIV;
}
- (UILabel *)cancleOrderL {
    
    if (!_cancleOrderL) {
        
        _cancleOrderL = [[UILabel alloc] init];
        _cancleOrderL.text = @"取消订单";
        _cancleOrderL.textColor = Color333333;
        _cancleOrderL.font = Font(24);
        _cancleOrderL.textAlignment = NSTextAlignmentCenter;
        _cancleOrderL.backgroundColor = WhiteColor;
        
    }
    
    return _cancleOrderL;
}

- (UIImageView *)payOrderIV {
    
    if (!_payOrderIV) {
        
        _payOrderIV = [[UIImageView alloc] init];
        _payOrderIV.contentMode = UIViewContentModeScaleAspectFit;
        _payOrderIV.image = [UIImage imageNamed:@"purchasePayBG"];
        
        _payOrderIV.userInteractionEnabled = YES;
        UITapGestureRecognizer *payOrderGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(payOrderGestureClick:)];
        [_payOrderIV addGestureRecognizer:payOrderGesture];
        
    }
    
    
    return _payOrderIV;
}
- (UILabel *)payOrderL {
    
    if (!_payOrderL) {
        
        _payOrderL = [[UILabel alloc] init];
        _payOrderL.textAlignment = NSTextAlignmentCenter;
        _payOrderL.textColor = WhiteColor;
        _payOrderL.text = @"立即支付";
        _payOrderL.font = Font(24);
        
    }
    
    return _payOrderL;
}

#pragma mark -设置
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];

    NSMutableArray *marr = [NSMutableArray arrayWithArray:self.navigationController.viewControllers];
    //判断移除填写地址信息controller
    for (UIViewController *vc in marr) {
        if ([vc isKindOfClass:[ShippingAddressAddViewController class]]) {
            [marr removeObject:vc];
            break;
        }
    }
    
    self.navigationController.viewControllers = marr;
//    self.navigationController.navigationBar.hidden = NO;
//    self.tabBarController.tabBar.hidden = NO;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
